package com.huaruan.youdi.views;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;


public class MainTabViewPager extends ViewPager {
    private boolean isScrollHorizonal = true;
    private boolean isAnimation = true;
    private float downX;

    public MainTabViewPager(Context context) {
        super(context);
    }

    public MainTabViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return this.isScrollHorizonal && super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN)
            downX = event.getX();
        return this.isScrollHorizonal && super.onInterceptTouchEvent(event);
    }

    public void setScrollHorizonal(boolean canScroll) {
        this.isScrollHorizonal = canScroll;
    }

    public void setAnimation(boolean animation) {
        isAnimation = animation;
    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
        super.setCurrentItem(item, isAnimation);
    }

    @Override
    public void setCurrentItem(int item) {
        super.setCurrentItem(item, isAnimation);
    }

    public float getDownX() {
        return downX;
    }

    public void resetDownX(float downX) {
        this.downX = downX;
    }
}
